//package com.example.huanglinqing.mqtt;
//
//import android.annotation.TargetApi;
//import android.app.Notification;
//import android.app.NotificationChannel;
//import android.app.NotificationChannelGroup;
//import android.app.NotificationManager;
//import android.app.PendingIntent;
//import android.content.Context;
//import android.content.Intent;
//import android.graphics.Color;
//import android.os.Build;
//import android.support.annotation.RequiresApi;
//import android.support.v4.app.NotificationCompat;
//import android.support.v4.app.TaskStackBuilder;
//import android.support.v7.app.AppCompatActivity;
//import android.os.Bundle;
//import android.text.TextUtils;
//import android.util.Log;
//import android.view.View;
//import android.widget.EditText;
//import android.widget.Toast;
//
//import com.example.huanglinqing.bean.MQTTMessage;
//import com.example.huanglinqing.service.MQTTService;
//
//import org.eclipse.paho.client.mqttv3.MqttCallback;
//import org.greenrobot.eventbus.EventBus;
//import org.greenrobot.eventbus.Subscribe;
//import org.greenrobot.eventbus.ThreadMode;
//
//import static android.app.Notification.BADGE_ICON_SMALL;
//
//public class MainActivity extends AppCompatActivity {
//    private NotificationManager mNotificationManager;
//private  NotificationChannel notificationChannel;
//    private String groupId = "groupId";
//    private CharSequence groupName = "Group1";
//
//    private String groupId2 = "groupId2";
//    private CharSequence groupName2 = "Group2";
//    private String chatChannelId2 = "chatChannelId2";
//    private String adChannelId2 = "adChannelId2";
//
//    private String chatChannelId = "chatChannelId";
//    private String chatChannelName = "聊天通知";
//    private String chatChannelDesc = "这是一个聊天通知，建议您置于开启状态，这样才不会漏掉朋友的消息哦";
//    private int chatChannelImportance = NotificationManager.IMPORTANCE_MAX;
//
//    private String adChannelId = "adChannelId";
//    private String adChannelName = "广告通知";
//    private String adChannelDesc = "这是一个广告通知，可以关闭的，但是如果您希望我们做出更好的软件服务于你，请打开广告支持一下吧";
//    private int adChannelImportance = NotificationManager.IMPORTANCE_LOW;
//    private String e;
//    private EditText editText;
//    @RequiresApi(api = Build.VERSION_CODES.O)
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
//    //   createGroup();
//        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//
//        EventBus.getDefault().register(this);
//        editText = (EditText) findViewById(R.id.content);
//        startService(new Intent(this, MQTTService.class));
//        findViewById(R.id.publishBtn).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (!TextUtils.isEmpty(editText.getText().toString()))
//                   MQTTService.publish(editText.getText().toString());
//
//
//            }
//
//        });
//        //createGroup();
//    }
//    @TargetApi(Build.VERSION_CODES.O)
//    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public void getMqttMessage(MQTTMessage mqttMessage) {
//        Log.i(MQTTService.TAG, "get message:" + mqttMessage.getMessage());
//        Toast.makeText(this, mqttMessage.getMessage(), Toast.LENGTH_SHORT).show();
//        e = mqttMessage.getMessage();
//        //  Intent intent = new Intent(this, MainActivity.class);
//        //  PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
////        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
////        Notification notification = new NotificationCompat.Builder(this)
////                .setContentTitle("111")
////                .setContentText("111;"+mqttMessage.getMessage())
////                .setWhen(System.currentTimeMillis())
////                .setSmallIcon(R.mipmap.ic_launcher)
////                //  .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
////        //        .setContentIntent(pi)
////                .setDefaults(Notification.DEFAULT_ALL)
////                //   .setStyle(new NotificationCompat.BigTextStyle().bigText(""+message))
////                .build();
////        notificationManager.notify(1, notification);
//
//        if (Build.VERSION.SDK_INT >= +Build.VERSION_CODES.O) {
//
//
//
//            createNotificationChannel(chatChannelId, chatChannelName, chatChannelImportance, chatChannelDesc, groupId);
////
//
//
//                mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(groupId, groupName));
////                mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(groupId2, groupName2));
//
//                createNotificationChannel(chatChannelId2, chatChannelName, chatChannelImportance, chatChannelDesc, groupId);
//  //              createNotificationChannel(adChannelId2, adChannelName, adChannelImportance, adChannelDesc, groupId);
//
//
//
//
//
//
//
//            Notification.Builder builder = new Notification.Builder(MainActivity.this, chatChannelId);
//            builder.setSmallIcon(R.mipmap.ic_launcher)
//                    .setContentTitle("这是标题")
//                    // .setContentText("Today released Android 8.0 version of its name is Oreo")
//                    .setContentText("内容是:" + e)
//                    // .setBadgeIconType(BADGE_ICON_SMALL)
//                    .setNumber(1)
//                    .setAutoCancel(true);
//
//            Intent resultIntent = new Intent(MainActivity.this, MainActivity.class);
//            TaskStackBuilder stackBuilder = TaskStackBuilder.create(MainActivity.this);
//            stackBuilder.addParentStack(MainActivity.class);
//            stackBuilder.addNextIntent(resultIntent);
//            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
//            builder.setContentIntent(resultPendingIntent);
//
//            mNotificationManager.notify((int) System.currentTimeMillis(), builder.build());
//// createGroup();
//        }else {
//////
//            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//        Notification notification = new NotificationCompat.Builder(this)
//                .setContentTitle("这是标题")
//                .setContentText("内容;"+e)
//                .setWhen(System.currentTimeMillis())
//                .setSmallIcon(R.mipmap.ic_launcher)
//                //  .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
//        //        .setContentIntent(pi)
//                .setDefaults(Notification.DEFAULT_ALL)
//                //   .setStyle(new NotificationCompat.BigTextStyle().bigText(""+message))
//                .build();
//        notificationManager.notify(1, notification);
//////
//////        }
////
//        }
//
//    }
//    @RequiresApi(api = Build.VERSION_CODES.O)
//    public void createNotificationChannel(String id, String name, int importance, String desc, String groupId) {
//        if (mNotificationManager.getNotificationChannel(id) != null) return;
////
//        NotificationChannel notificationChannel = new NotificationChannel(id, name, importance);
//        notificationChannel.enableLights(true);
//        notificationChannel.enableVibration(true);
//
//        notificationChannel.setLightColor(Color.RED);
//        notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
//        notificationChannel.setShowBadge(true);
//        notificationChannel.setBypassDnd(true);
//        notificationChannel.setVibrationPattern(new long[]{100, 200, 300, 400});
//        notificationChannel.setDescription(desc);
//        notificationChannel.setGroup(groupId);
//        //    notificationChannel.setSound();
//
//        mNotificationManager.createNotificationChannel(notificationChannel);
//    }
//
//
////    @RequiresApi(api = Build.VERSION_CODES.O)
////    public void createGroup() {
////        mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(groupId, groupName));
////        mNotificationManager.createNotificationChannelGroup(new NotificationChannelGroup(groupId2, groupName2));
////
////        createNotificationChannel(chatChannelId2, chatChannelName, chatChannelImportance, chatChannelDesc, groupId);
////        createNotificationChannel(adChannelId2, adChannelName, adChannelImportance, adChannelDesc, groupId);
////    }
//
//    @Override
//    protected void onDestroy() {
//        EventBus.getDefault().unregister(this);
//        super.onDestroy();
//    }
//}
